
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbFlowFlowNodeMiddleDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlowFlowNodeMiddle tbFlowFlowNodeMiddle=null;
    private List<TbFlowFlowNodeMiddle> tbFlowFlowNodeMiddleList=null;

    public boolean add(TbFlowFlowNodeMiddle inTbFlowFlowNodeMiddle){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_FlowFlowNodeMiddle(FlowFlowNodeMiddleSeq,FlowId,FlowNodeId,UserId) values(?,?,?,?)";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowFlowNodeMiddle.getFlowFlowNodeMiddleSeq());
        pt.setInt(2,inTbFlowFlowNodeMiddle.getFlowId());
        pt.setInt(3,inTbFlowFlowNodeMiddle.getFlowNodeId());
        pt.setInt(4,inTbFlowFlowNodeMiddle.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowFlowNodeMiddleId){
        return UtilDAO.del("Tb_FlowFlowNodeMiddle", "FlowFlowNodeMiddleId", inFlowFlowNodeMiddleId);
    }
    public boolean edit(TbFlowFlowNodeMiddle inTbFlowFlowNodeMiddle){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_FlowFlowNodeMiddle set FlowFlowNodeMiddleSeq=?,FlowId=?,FlowNodeId=?,UserId=?,CreateTime=getdate() where FlowFlowNodeMiddleId=?";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbFlowFlowNodeMiddle.getFlowFlowNodeMiddleSeq());
        pt.setInt(2,inTbFlowFlowNodeMiddle.getFlowId());
        pt.setInt(3,inTbFlowFlowNodeMiddle.getFlowNodeId());
        pt.setInt(4,inTbFlowFlowNodeMiddle.getUserId());
        pt.setInt(5,inTbFlowFlowNodeMiddle.getFlowFlowNodeMiddleId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlowFlowNodeMiddle getTbFlowFlowNodeMiddleByFlowFlowNodeMiddleId(int inFlowFlowNodeMiddleId) {
        tbFlowFlowNodeMiddle=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowFlowNodeMiddle where FlowFlowNodeMiddleId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowFlowNodeMiddleId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlowFlowNodeMiddle == null)tbFlowFlowNodeMiddle = getTbFlowFlowNodeMiddle(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowFlowNodeMiddle;
    }
    public List<TbFlowFlowNodeMiddle> getTbFlowFlowNodeMiddleByFlowId(int inFlowId) {
        tbFlowFlowNodeMiddleList=new ArrayList<TbFlowFlowNodeMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowFlowNodeMiddle where FlowId=? order by FlowFlowNodeMiddleSeq";
            pt = conn.prepareStatement(sql);
            pt.setInt(1, inFlowId);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowFlowNodeMiddleList.add(getTbFlowFlowNodeMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowFlowNodeMiddleList;
    }
    public List<TbFlowFlowNodeMiddle> getTbFlowFlowNodeMiddleAll() {
        tbFlowFlowNodeMiddleList=new ArrayList<TbFlowFlowNodeMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowFlowNodeMiddle";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowFlowNodeMiddleList.add(getTbFlowFlowNodeMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowFlowNodeMiddleList;
    }
    public List<TbFlowFlowNodeMiddle> getTbFlowFlowNodeMiddleAll(VskPage vp) {
        tbFlowFlowNodeMiddleList=new ArrayList<TbFlowFlowNodeMiddle>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowFlowNodeMiddle";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_FlowFlowNodeMiddle", "FlowFlowNodeMiddleId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowFlowNodeMiddleList.add(getTbFlowFlowNodeMiddle(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowFlowNodeMiddleList;
    }
    public TbFlowFlowNodeMiddle getTbFlowFlowNodeMiddle(ResultSet rs) throws Exception{
        TbFlowFlowNodeMiddle tbFlowFlowNodeMiddle = new TbFlowFlowNodeMiddle();
        tbFlowFlowNodeMiddle.setFlowFlowNodeMiddleId(rs.getInt("FlowFlowNodeMiddleId"));
        tbFlowFlowNodeMiddle.setFlowFlowNodeMiddleSeq(rs.getInt("FlowFlowNodeMiddleSeq"));
        tbFlowFlowNodeMiddle.setFlowId(rs.getInt("FlowId"));
        tbFlowFlowNodeMiddle.setFlowNodeId(rs.getInt("FlowNodeId"));
        tbFlowFlowNodeMiddle.setUserId(rs.getInt("UserId"));
        tbFlowFlowNodeMiddle.setCreateTime(rs.getString("CreateTime"));
        return tbFlowFlowNodeMiddle;
    }
    public static void main(String[] args) {
		List<TbFlowFlowNodeMiddle> ffnmlist=new TbFlowFlowNodeMiddleDAO().getTbFlowFlowNodeMiddleByFlowId(1);
		System.out.println(ffnmlist.size());
	}
}
